package com.magic.smartcity.view.more.viewmodels

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.magic.smartcity.beans.*
import com.magic.smartcity.view.more.models.HospitalModel

/**
 * @description:
 * @create: Create by Magic on 2022/2/19.
 */
class HospitalViewModel() : ViewModel() {

    private val model = HospitalModel()

    private val TAG: String = "HospitalViewModel"

    val hospitalBannerList: MutableLiveData<List<HospitalBanner>> = MutableLiveData()
    val hospitalList: MutableLiveData<List<HospitalDetail>> = MutableLiveData()
    val hospitalDetail: MutableLiveData<HospitalDetail> = MutableLiveData()
    val hospitalPatientCardList: MutableLiveData<List<HospitalPatientCard>> =
        MutableLiveData()
    val addHospitalPatientCardOk: MutableLiveData<String> = MutableLiveData()
    val editHospitalPatientCardOk: MutableLiveData<String> = MutableLiveData()

    val departments: MutableLiveData<List<HospitalDepartments>> = MutableLiveData()
    val submitReserve: MutableLiveData<String> = MutableLiveData()

    fun getHospitalBanner(hospitalId: Int) {
        model.getHospitalBanner(hospitalId, success = {
            hospitalBannerList.postValue(it)
        }, error = {})
    }

    fun getHospitalList() {
        model.getHospitalList(success = {
            hospitalList.postValue(it)
        }, error = {})
    }

    fun getHospitalById(hospitalId: Int) {
        model.getHospitalDetailById(hospitalId, success = {
            hospitalDetail.postValue(it)
        }, error = {})
    }

    fun getPatientCardList() {
        model.getHospitalPatientCardList(success = {
            hospitalPatientCardList.postValue(it)
        }, error = {})
    }

    fun addHospitalPatinentCard(
        name: String,
        address: String,
        birthday: String,
        phoneNumber: String,
        idCard: String,
        sex: String
    ) {
        val hospitalPatientCard = HospitalPatientCard()
        hospitalPatientCard.name = name
        hospitalPatientCard.address = address
        hospitalPatientCard.birthday = birthday
        hospitalPatientCard.tel = phoneNumber
        hospitalPatientCard.cardId = idCard
        hospitalPatientCard.sex = sex
        model.addPatientCard(hospitalPatientCard, success = {
            addHospitalPatientCardOk.postValue(it)
        }, error = {})

    }

    fun editHospitalPatientCard(hospitalPatientCard: HospitalPatientCard) {
        model.editPatientCard(hospitalPatientCard, success = {
            editHospitalPatientCardOk.postValue(it)
        }, error = {})
    }

    fun getDepartments() {
        model.getDepartments(success = {
            departments.postValue(it)
        }, error = {})
    }

    fun getDepartments(typeId: Int) {
        model.getDepartments(success = {
            departments.postValue(it)
        }, error = {})
    }

    fun submitPatientReserve(
        categoryId: Int,
        money: Int,
        patientName: String,
        reserveTime: String,
        type: String
    ) {
        val reserve = HospitalPatientReserve()
        reserve.categoryId = categoryId
        reserve.money = money
        reserve.patientName = patientName
        reserve.reserveTime = reserveTime
        reserve.type = type
        model.submitPatientReserve(reserve, success = {
            submitReserve.postValue(it)
        }, error = {})
    }

}